import { WeaSearchGroup,WeaFormItem } from 'ecCom';
import { Button } from 'antd';
import {toJS} from "mobx"
import {WeaSwitch} from "comsMobx"
import { inject, observer} from 'mobx-react';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class Condition extends React.Component{

    constructor(props){
        super(props);
        this.formParams = {};
    }

    render(){
        const { condition } = this.props.listStore;
        const {form,onEnterSearch} = this.props;
        const {isFormInit} = form;
        let group = [];
        const formParamsTemp = form.getFormParams();
        for(let param in formParamsTemp){
            this.formParams[param] = formParamsTemp[param];
        }
        isFormInit && condition.map((c,i) =>{
          let items = [];
          c.items.map((fields,index) => {
            items.push({
              com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@aaol08@${fields.domkey[0]}`}
                  label={`${fields.label}`}
                  labelCol={{span: `${fields.labelcol}`}}
                  wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@i19on8@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams} onEnterSearch={onEnterSearch}/>
                  </WeaFormItem>),
              colSpan:1,
            })
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@pd6zqm@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }
}

const getAdButtons = (listStore,form) => {
  const {doSearch,setShowSearchAd,clearFormFields,setSelectedTreeKey} = listStore;
	return [
		(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@51ude5@search`} type="primary" onClick={()=>{setSelectedTreeKey&&form&&setSelectedTreeKey("sec_"+form.getFormParams().capitalgroupid);doSearch();setShowSearchAd(false);}}>{getLabel(197,"搜索")}</Button>),
		(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@juz9hl@reset`} type="ghost" onClick={()=>{clearFormFields();}}>{getLabel(2022,"重置")}</Button>),
		(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@xr867r@close`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>{getLabel(201,"取消")}</Button>)
	];
}

export {Condition,getAdButtons}
